<template>
    <Form
            ref="form"
            :form-items="formItems"
    ></Form>
</template>

<script>
    import Form from '../../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'appCode'
                        },
                        element:{
                            type: 'select',
                            select:{
                                url: this.$baseURL.wx + '/wx/mp/config/list',
                                optionProp:{
                                    value: 'appCode',
                                    label: 'appName'
                                }
                            },
                            required: true,
                            label: '公众号',
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: this.clearQuota,
                                    code: 'clearQuotaButtonCode',
                                    label: '公众号api调用次数清零'
                                },
                            ]
                        }
                    }
                ]
            }
        },
        methods:{
            clearQuota(){
                this.$refs.form.validateAndSubmitForm((form)=>{
                    this.$refs.form.setButtonLoading('clearQuotaButtonCode',true)
                    this.axios.post(this.$baseURL.wx + '/wx/mp/helper/'+ form.appCode + '/clear/quota')
                    .then((res)=>{
                        this.$message.success('清零成功')
                    }).catch(error=>{
                        if(error.response){
                            this.$message.error(error.response.data.msg)
                        }else {
                            this.$message.error('网络错误或服务不可用')
                        }
                    })
                        .finally(()=>{
                            this.$refs.form.setButtonLoading('clearQuotaButtonCode',false)
                        })
                })
            }
        }
    }
</script>

<style scoped>

</style>